﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Appointments.SelfServiceTerminal;
using YaAppoint.Response;

namespace YaAppoint.Web.Controllers
{
    public class SelfServiceController(ISelfServiceAppService selfServiceAppService) : AbpControllerBase
    {
        private readonly ISelfServiceAppService _selfServiceAppService = selfServiceAppService;

        /// <summary>
        /// 获取自助机IP
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet("/api/self-service/get-client-ip")]
        public IActionResult GetRequestIp()
        {
            var res = new BackJson();
            res.code = 0;
            res.data = new
            {
                ip = HttpContext.Connection.RemoteIpAddress!.ToString()
            };
            return new JsonResult(res);
        }

        /// <summary>
        /// 签到
        /// </summary>
        [AllowAnonymous]
        [HttpPost("/api/self-service/check-in")]
        public async Task<IActionResult> CheckIn([FromBody]CheckInDto dto) 
        {
            return new JsonResult(await _selfServiceAppService.CheckIn(dto.numbers, dto.DepCodes));
        }

        /// <summary>
        /// 获取预约信息
        /// </summary>
        [AllowAnonymous]
        [HttpPost("/api/self-service/get-appointment-info")]
        public async Task<IActionResult> GetAppointment([FromBody]CheckInDto dto)
        {
            return new JsonResult(await _selfServiceAppService.GetAppointmentInfo(dto.numbers, dto.DepCodes));
        }


        /// <summary>
        /// 重新打印签到小票
        /// </summary>
        [AllowAnonymous]
        [HttpGet("/api/self-service/reprint-check-in")]
        public async Task<IActionResult> RePrint(string appointNumber)
        {
            return new JsonResult(await _selfServiceAppService.RePrint(appointNumber));
        }
    }


    /// <summary>
    /// 签到Dto
    /// </summary>
    public class CheckInDto
    { 
        public string numbers { get; set; }

        public string DepCodes { get; set; }
    }
}
